package com.itcast.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itcast.mapper.ClazzMapper;
import com.itcast.pojo.Clazz;
import com.itcast.pojo.ClazzQueryParam;
import com.itcast.pojo.PageBean;
import com.itcast.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 查询班级信息(条件)
     * @param param
     * @return
     */
    public PageBean listQuery(ClazzQueryParam param) {
        PageHelper.startPage(param.getPage(),param.getPageSize());
        Page<Clazz> rows = clazzMapper.listQuery(param);
        return new PageBean(rows.getTotal(),rows);
    }

    /**
     * 删除班级
     * @param id
     * @return
     */
    public void delete(Integer id) {
        clazzMapper.delete(id);
    }

    /**
     * 新增班级
     * @return
     */
    public void add(Clazz clazz) {
        clazzMapper.add(clazz);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public Clazz getById(Integer id) {
        return clazzMapper.getById(id);
    }

    /**
     * 修改班级
     * @return
     */
    public void update(Clazz clazz) {
        clazzMapper.update(clazz);
    }

    /**
     * 查询所有班级
     * @return
     */
    public List<Clazz> list() {
        return clazzMapper.list();
    }
}
